package org.csu.mypetstore.controller;

import jakarta.servlet.http.HttpSession;
import org.csu.mypetstore.domain.Order;
import org.springframework.ui.Model;
import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/order/results")
public class OrderResultController  {

    @Autowired
    private OrderService orderService;

    // 显示订单结果
    @GetMapping
    public String showResults(
            //@SessionAttribute Account account,
            HttpSession session,
            Model model) {

        Account account= (Account) session.getAttribute("loginAccount");
        List<Order> orders = orderService.getOrderHistory(account.getUsername());
        model.addAttribute("orderList", orders);
        return "order/orderResults";
    }
}